import { useIntersectionObserver } from '@vueuse/core'
import { ref } from 'vue'

export function useObserve (apiFn) {
	const target = ref(null)

	const { stop } = useIntersectionObserver(
		target,
		([{ isIntersecting }]) => {
			if (isIntersecting) {
				// 发请求方法
				apiFn()
				// 关闭监控
				stop()
			}
		},

		{
			threshold: 0 // 阈值0-1
		}
	)

	return { target }
}